using Engine;
using Game;

namespace SCIENEW {
    /// <summary>
    /// 矿石粉末
    /// </summary>
    public class OrePowderItem : FlatItem, IMaterialBlock {
        public static readonly Color[] Colors = new[]
        {
            Color.Black,
            Color.White,
            new Color(255, 215, 0),
            new Color(212, 212, 212),
            new Color(87, 86, 85),
            new Color(232, 232, 232),
            new Color(64, 224, 205),
            new Color(225, 225, 225),
            new Color(60, 60, 60),
            Color.White,
            new Color(120, 120, 120),
            new Color(199, 97, 20),
            Color.LightGreen,
            Color.White,
            new Color(139, 69, 19),
            new Color(34, 139, 34),
            Color.White,
            new Color(205, 190, 112),
            Color.White,
            Color.White,
            Color.White,
            Color.DarkYellow,
        };

        public Materials Material = Materials.Iron;

        public Materials GetMaterial() => Material;

        bool createRecipe;

        public OrePowderItem(Materials type, bool createRecipe = true) : this(type + "OrePowder", Colors[(int)type], createRecipe: createRecipe) {
            Material = type;
            DisplayName = string.Format(LanguageControl.Get("Items", "Names", "OrePowderItem"), Material.ToDisplayName());
            Description = string.Format(LanguageControl.Get("Items", "Descriptions", "OrePowderItem"), Material.ToDisplayName());
        }

        public OrePowderItem(string id, Color color, bool createRecipe = true) : base(id) {
            Material = Materials.None;
            Id = id;
            Color = color;
            DefaultTextureSlot = 198;
            this.createRecipe = createRecipe;
        }

        public override CraftingRecipe[] GenerateProceduralRecipe(int value) {
            if (!createRecipe) return base.GenerateProceduralRecipe(value);
            //矿石到粉
            if (Material == Materials.None) return base.GenerateProceduralRecipe(value);
            CraftingRecipe craftingRecipe = new CraftingRecipe {
                Description = $"在粉碎机把{Material.ToDisplayName()}矿石磨成粉",
                Ingredients = new string[36],
                RemainsValue = 0,
                RemainsCount = 0,
                RequiredHeatLevel = ComponentKibbler.RequiredHeatLevel,
                RequiredPlayerLevel = 0,
                ResultValue = ItemsBlockManager.GetItemID(this),
                ResultCount = 2,
            };
            craftingRecipe.Ingredients[0] = IECraftingRecipesManager.BlockToIngredient(ItemsBlockManager.GetItemIdByMaterial<OreChunkItem>(Material));
            return [craftingRecipe];
        }
    }
}